package com.aps.service.rep;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.aps.entity.domain.order.OrderDish;
import com.aps.entity.dto.ApsOrderDishDbDTO;
import com.aps.entity.eunm.DishStatus;
import com.aps.entity.eunm.OrderStatus;

import java.util.Date;
import java.util.List;

/**
 * 
 */
public interface OrderDishRep extends JpaRepository<OrderDish, String> {

    OrderDish findByOrderNumAndDishNumAndDishSeq(String orderNum, String dishNum, String dishSeq);

    OrderDish findByOrderNumAndDishSeq(String orderNum, String dishSeq);

    Integer countByOrderNumAndStatus(String orderNum, DishStatus status);

    Integer countByOrderNumAndStatusNotAndStatusNot(String orderNum, OrderStatus status1,
            OrderStatus status2);

    @Query(value = "select new com.aps.entity.dto.ApsOrderDishDbDTO(d, od) from Dish d, OrderDish od where od.dishNum = d.code and od.orderNum = ?1")
    List<ApsOrderDishDbDTO> findDishByDishNum(String orderNum);

    @Query(value = "select min(od.completeTime) from OrderDish od where od.deviceModuleCode = ?1")
    Date enableTime(String deviceModuleCode);

}
